package interfaces;

import java.lang.reflect.Field;
import java.util.Collection;

import org.osgi.framework.BundleContext;

import annotations.LongStringAnnotationProvider;
import annotations.LongStringProvider;
import windows.ObjectWindow;
import windows.Window;

public class Controller {
	private BundleContext bundleContext;
	private LongStringProvider longStringProvider;
	
	public Controller(Object object, BundleContext bundleContext){
		this.bundleContext = bundleContext;
		longStringProvider = new LongStringAnnotationProvider();
		if(gotCollections(object)){
			new Window(object, this);
		} else {
			new ObjectWindow(object, this);
		}
	}
	
	public BundleContext getBundleContext(){
		return bundleContext;
	}
	
	public LongStringProvider getLongStringProvider(){
		return longStringProvider;
	}
	
	public void setLongStringProvider(LongStringProvider longStringProvider) {
		this.longStringProvider = longStringProvider;
	}

	public boolean gotCollections(Object object){
		Class<?> c = object.getClass();
		for (Field field : c.getDeclaredFields()) {
			if(Collection.class.isAssignableFrom(field.getType())){
				return true;
			}
		}
		return false;
	}
}